import Vue from 'vue'
import Router from 'vue-router'
import Home from "@/views/home/home.vue"
import City from "@/views/city/city"
import Discount from "@/views/discount/discount"
import Car from "@/views/car/car"
import New from "@/views/new/new"
import Order from "@/views/order/order"
import Shop from "@/views/shop/shop"
import Detail from "@/views/detail/detail"
import Layout from "@/views/layout/layout"
import Meorder from "@/views/layout/view/meorder"
import Adress from "@/views/layout/view/adress"
import Personage from "@/views/layout/view/personage"
import Balance from "@/views/layout/view/balance"
import Password from "@/views/layout/view/password"
import balancepay from "@/views/layout/view/balancepay"
import Integral from "@/views/layout/view/integral"
import Orderdetail from "@/views/orderdetail/orderdetail"
import Evaluate from "@/views/evaluate/evaluate"
import Sale from "@/views/sale/sale"
import Newdetail from "@/views/newdetail/newdetail"
import Login from "@/views/login/login"
import Pay from "@/views/pay/pay"
import Logistics from "@/views/logistics/logistics"
import Evaluatedetail from "@/views/evaluatedetail/evaluatedetail"
import Saledetail from "@/views/saledetail/saledetail"
import List from "@/views/list/list"
import Search from "@/views/search/search"
import none from "@/views/404/404"

import RemoveWatermark from "../views/remove_watermark/RemoveWatermark.vue";

import wechatPay from "../views/pay/wechatPay.vue";
import video from "../views/video/Video.vue";
import GptPage from "../views/chat/GptPage.vue";
import introduce from "../views/introduce/introduce.vue";
import SourcePage from "../views/source_page/SourcePage.vue";
import TaskPage from "../views/task_page/TaskPage.vue";

Vue.use(Router)
const router = new Router({
  routes: [{
    path: '/',
    redirect: "/home"
  },
    {
      path: '/TaskPage',
      name: 'TaskPage',
      component: TaskPage,
      meta: {
        title: "TaskPage"
      }
    },
    {
      path: '/SourcePage',
      name: 'SourcePage',
      component: SourcePage,
      meta: {
        title: "SourcePage"
      }
    },
    {
      path: '/introduce',
      name: 'introduce',
      component: introduce,
      meta: {
        title: "introduce"
      }
    },
    {
      path: '/gpt',
      name: 'gpt',
      component: GptPage,
      meta: {
        title: "gpt"
      }
    },
    {
      path: '/video',
      name: 'video',
      component: video,
      meta: {
        title: "视频中心"
      }
    },
    {
      path: '/RemoveWatermark',
      name: 'RemoveWatermark',
      component: RemoveWatermark,
      meta: {
        title: "去水印"
      }
    },
    {
      path: '/home',
      name: 'home',
      component: Home,
      meta: {
        title: "首页"
      }
    },
    {
      path: '/pay',
      name: 'pay',
      component: Pay,
      meta: {
        title: "支付"
      }
    },
    {
      path: '/wechatPay',
      name: 'pay',
      component: wechatPay,
      meta: {
        title: "微信支付"
      }
    },
    {
      path: '/saledetail',
      name: 'saledetail',
      component: Saledetail,
      meta: {
        title: "售后详情"
      }
    },
    {
      path: '/evaluatedetail',
      name: 'evaluatedetail',
      component: Evaluatedetail,
      meta: {
        title: "评价详情"
      }
    },
    {
      path: '/logistics',
      name: 'logistics',
      component: Logistics,
      meta: {
        title: "物流信息"
      }
    },
    {
      path: "/evaluate",
      name: "evaluate",
      component: Evaluate,
      meta: {
        title: "评价"
      }
    },
    {
      path: "/login",
      name: "login",
      component: Login,
      meta: {
        title: "登录"
      }
    },
    {
      path: "/newdetail",
      name: "newdetail",
      component: Newdetail,
      meta: {
        title: "新闻详情"
      }
    },
    {
      path: "/sale",
      name: "sale",
      component: Sale,
      meta: {
        title: "申请售后"
      }
    },
    {
      path: "/orderdetail",
      name: "orderdetail",
      component: Orderdetail,
      meta: {
        title: "订单的详情"
      }
    },
    {
      path: "/order",
      name: "order",
      component: Order,
      meta: {
        title: "我的订单"
      }
    },
    {
      path: '/city',
      name: 'city',
      component: City,
      meta: {
        title: "城市分站"
      }
    },
    {
      path: '/detail',
      name: 'detail',
      component: Detail,
      meta: {
        title: "商品详情"
      }
    },
    {
      path: '/discount',
      name: 'discount',
      component: Discount,
      meta: {
        title: "优惠券"
      }
    },
    {
      path: '/car',
      name: 'car',
      component: Car,
      meta: {
        title: "购物车"
      }
    },
    {
      path: "/new",
      name: "new",
      component: New,
      meta: {
        title: "新闻中心"
      }
    },
    {
      path: "/shop",
      name: "shop",
      component: Shop,
      meta: {
        title: "商家入驻"
      }
    },
    {
      path: "/search",
      name: "search",
      component: Search,
      meta: {
        title: "搜索"
      }
    },
    {
      path: "/list",
      name: "list",
      component: List,
      meta: {
        title: "商品列表"
      }
    }, {
      path: "/404",
      name: "none",
      component: none,
      meta: {
        title: "404"
      }
    },
    {
      path: "/layout",
      name: "layout",
      component: Layout,
      redirect: "/layout/meorder",
      children: [{
        path: "meorder",
        component: Meorder,
        meta: {
          title: "我的订单"
        }
      },
        {
          path: "adress",
          component: Adress,
          meta: {
            title: "收货地址"
          }
        },
        {
          path: "password",
          component: Password,
          meta: {
            title: "修改密码"
          }
        },
        {
          path: "balancepay",
          component: balancepay,
          meta: {
            title: "充值中心"
          }
        },
        {
          path: "personage",
          component: Personage,
          meta: {
            title: "个人信息"
          }
        },
        {
          path: "balance",
          component: Balance,
          meta: {
            title: "零钱"
          }
        },
        {
          path: "integral",
          component: Integral,
          meta: {
            title: "积分"
          }
        }
      ]
    }

  ],
  scrollBehavior(to, from, savedPosition) {
    // 期望滚动到哪个位置
    return {
      x: 0,
      y: 0
    }
  }
})

const VueRouterPush = Router.prototype.push
Router.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
router.afterEach((to, from) => {
  document.title = to.meta.title //在全局后置守卫中获取路由元信息设置title
})
export default router
